package com.ruoyi.business.service.impl;

import java.util.List;

import com.ruoyi.business.domain.*;
import com.ruoyi.business.mapper.BusContractMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.BusContractDeliveryMapper;
import com.ruoyi.business.service.IBusContractDeliveryService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 合同交货Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@Service
public class BusContractDeliveryServiceImpl implements IBusContractDeliveryService 
{
    @Autowired
    private BusContractDeliveryMapper busContractDeliveryMapper;

    @Autowired
    private BusContractMapper busContractMapper;

    /**
     * 查询合同交货
     * 
     * @param deliveryId 合同交货主键
     * @return 合同交货
     */
    @Override
    public BusContractDelivery selectBusContractDeliveryByDeliveryId(Long deliveryId)
    {
        return busContractDeliveryMapper.selectBusContractDeliveryByDeliveryId(deliveryId);
    }

    /**
     * 查询合同交货列表
     * 
     * @param busContractDelivery 合同交货
     * @return 合同交货
     */
    @Override
    public List<BusContractDelivery> selectBusContractDeliveryList(BusContractDelivery busContractDelivery)
    {
        return busContractDeliveryMapper.selectBusContractDeliveryList(busContractDelivery);
    }

    /**
     * 新增合同交货
     * 
     * @param busContractDelivery 合同交货
     * @return 结果
     */
    @Override
    @Transactional
    public int insertBusContractDelivery(BusContractDelivery busContractDelivery)
    {
        busContractDelivery.setCreateTime(DateUtils.getNowDate());
        int result = busContractDeliveryMapper.insertBusContractDelivery(busContractDelivery);
        busContractMapper.updateContractCompleteType(busContractDelivery.getContractId());

        return result;
    }

    /**
     * 修改合同交货
     * 
     * @param busContractDelivery 合同交货
     * @return 结果
     */
    @Override
    public int updateBusContractDelivery(BusContractDelivery busContractDelivery)
    {
        busContractDelivery.setUpdateTime(DateUtils.getNowDate());
        return busContractDeliveryMapper.updateBusContractDelivery(busContractDelivery);
    }

    /**
     * 批量删除合同交货
     * 
     * @param deliveryIds 需要删除的合同交货主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteBusContractDeliveryByDeliveryIds(Long[] deliveryIds)
    {
        BusContractDelivery busContractDelivery = busContractDeliveryMapper.selectBusContractDeliveryByDeliveryId(deliveryIds[0]);
        int result =  busContractDeliveryMapper.deleteBusContractDeliveryByDeliveryIds(deliveryIds);
        busContractMapper.updateContractCompleteType(busContractDelivery.getContractId());

        return result;
    }

    /**
     * 删除合同交货信息
     * 
     * @param deliveryId 合同交货主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteBusContractDeliveryByDeliveryId(Long deliveryId)
    {
        BusContractDelivery busContractDelivery = busContractDeliveryMapper.selectBusContractDeliveryByDeliveryId(deliveryId);
        int result =  busContractDeliveryMapper.deleteBusContractDeliveryByDeliveryId(deliveryId);
        busContractMapper.updateContractCompleteType(busContractDelivery.getContractId());

        return result;

    }

    /**
     * 获取合同交货列表信息
     * @return
     */
    @Override
    public List<BusContractDeliveryDetail>  getContractDeliveryList(BusContractDeliveryParam busContractDeliveryParam){
        return busContractDeliveryMapper.getContractDeliveryList(busContractDeliveryParam);
    }
}
